import * as Types from "./mutations-types"
import axios from "axios"
import { Base64 } from 'js-base64';
const actions={
  addPlayList({commit},mid){
    console.log("1111")
    //根据mid获取这首歌的图片
    axios.get('/apig/cgi-bin/musicu.fcg',{
      params:{
        "-": "getUCGI8812487901985184",
        g_tk: 422380832,
        loginUin: 0,
        hostUin: 0,
        format: "json",
        inCharset: "utf8",
        outCharset: "utf-8",
        notice: 0,
        platform:"yqq.json",
        needNewCode: 0,
        data: {
          "comm":{
            "ct":24,
            "cv":0
          },
          "songinfo":{
            "method":"get_song_detail_yqq",
            "param":{
              "song_type":0,
              "song_mid":mid,
              "song_id":228859369},
              "module":"music.pf_song_detail_svr"
          }
        }
      }
    })
    .then(res=>{
      var Singerinfo=res.data.songinfo.data.track_info
      let imgages='y.gtimg.cn/music/photo_new/T002R300x300M000'+res.data.songinfo.data.track_info.album.mid+'.jpg?max_age=2592000'
      // console.log(imgages)
      //根据mid获取这首歌的播放地址
      axios.get('/apig/cgi-bin/musicu.fcg',{
        params:{
          "-": "getplaysongvkey8302100569597644",
          g_tk: 422380832,
          loginUin: 0,
          hostUin: 0,
          format: "json",
          inCharset: "utf8",
          outCharset: "utf-8",
          notice: 0,
          platform:"yqq.json",
          needNewCode: 0,
          data: {
            "req":{
              "module":"CDN.SrfCdnDispatchServer",
              "method":"GetCdnDispatch",
              "param":{
                "guid":"3404826530",
                "calltype":0,
                "userip":""
              }
            },
            "req_0":{
              "module":"vkey.GetVkeyServer",
              "method":"CgiGetVkey",
              "param":{
                "guid":"3404826530",
                "songmid":[mid],
                "songtype":[0],
                "uin":"1580313879",
                "loginflag":1,
                "platform":
                "20"
              }
            },
            "comm":{
              "uin":1580313879,
              "format":
              "json",
              "ct":24,
              "cv":0
            }
          }
        }
      })
      .then(res=>{
        // console.log(res)
        let httpurls=res.data.req_0.data.sip[1]
        let urls=res.data.req_0.data.midurlinfo[0].purl
        // console.log(httpurls+urls)
        if(!urls){
          console.log("无法播放")
        }
        else{
          axios.get("https://v1.itooi.cn/tencent/lrc?",{
            params:{
              id:mid
            }
          })
          .then((respos)=>{
            // console.log(respos.data.lyric)
            //获取歌词
            let lyric=respos.data;
            //所有数据传入MySonInfo对象
            let MySonInfo={
              Singerinof:Singerinfo,
              Singerimgages:imgages,
              SingerUrl:httpurls+urls,
              lyric:lyric
            }
            //提交当前这首歌的整个信息
            commit(Types.ADD_PLATLIST,MySonInfo)
          })
        }
      })
      // console.log(res.data.songinfo.data.track_info.album.mid)
    })
    // commit(Types.ADD_PLATLIST,mid)
  }
}
export default actions;
